    <!-- Advance table -->
    <script src="<?=$url_styles?>js/plugins/tables/jquery.dataTables.min.js"></script>
    <script src="<?=$url_styles?>js/plugins/tables/colResizable-1.3.min.js"></script>
    <script src="<?=$url_styles?>js/plugins/tables/jquery.tablesorter.min.js"></script> 
    <script src="<?=$url_styles?>js/plugins/formselements/jquery.ibutton.min.js"></script>  
    <script src="<?=$url_styles?>js/plugins/formselements/ui.spinner.min.js"></script> 
    <script>
        /*oTable = $('#module_table').dataTable({		
            "sPaginationType": "full_numbers"
        });*/
        
        /* --->> 9 - OS Styling --------------*/
        function load_ibutton(){
            $(".os_chbox").iButton({
                change: function(e)
                {
					if(typeof(e.attr('data'))=='undefined') return;
                    $.ajax({
                       url: '<?=url_create('admin','system','set_state')?>',
                       dataType: 'json',
                       type: 'post',
                       data: { 
                           id: e.attr('data'),
                           active: e.attr('checked')=='checked'?1:0
                       },
                       success: function(o)
                       {
                           if(o.state=='success')
                           {
                               str = $('#row_'+e.attr('data')).attr('class');
                               if(e.attr('checked')=='checked') 
                                   str = 'gradeA '+str.split(' ')[1];
                               else
                                   str = 'gradeX '+str.split(' ')[1];

                               $('#row_'+o.id).attr('class',str);
                           }
                           else{
                               $.jGrowl(o.message, {
                                   header: o.title,
                                   theme:"notification_styled_"+o.state 
                               });
                           }
                       }
                    });
					return false;
                }
            });
        }
        function load_module_table()
        {
            $.ajax({
               url: '<?=url_create('admin','system','read')?>',
               dataType: 'json',
               type: 'post',
               success: function(o)
               {
                   if(o.state=='success'){
                       var str='';
                       for(var i in o.data){
                           var r=o.data[i];
						   var row_class = (r.active==1)?'A':'X';
						   if(i%2==1) row_class+=" odd";
                           var checked_active = (r.active==1)?'checked':'';
                           str+='<tr id="row_'+r.id+'" class="grade'+row_class+'">'+
                                  '<td>'+r.pre+r.name+'</td>'+
                                  '<td>'+r.controller+'</td>'+
                                  '<td>'+r.class+'</td>'+
                                  '<td>'+r.index+'</td>'+
                                  '<td><input data="'+r.id+'" class="os_chbox" type="checkbox" '+checked_active+'/></td>'+
                                  '<td class="center"><a href="#module_modal" data="'+r.id+'" class="btn btn-mini btn-success module_edit"><?=lang('edit')?></a>&nbsp;<button class="btn btn-mini btn-danger module_delete" data="'+r.id+'"><?=lang('delete')?></button></td>'+
                              '</tr>';
                       }
                       $('#module_table tbody').html(str);
                       load_ibutton();
                   }
               }
            });
        }
		
        $('.module_delete').live('click',function(e){
            if(confirm('<?=lang('delete_confirm')?>'))
            {
                $.ajax({
                   url: '<?=url_create('admin','system','delete')?>',
                   type: 'post' ,
                   dataType: 'json',
                   data:{id: $(this).attr('data')},
                   success:function(o)
                   {
                       if(o.state == 'success')
                           $('#row_'+o.id).fadeOut(500);
                       else
                           $.jGrowl(o.message, {
                               header: o.title,
                               theme:"notification_styled_"+o.state 
                           });
                   }
                });
             }
        });
        
        $('.module_edit').live('click',function(e){
			$('#module_modal').attr('flag','edit');
			$('#module_modal').attr('module_id',$(this).attr('data'));
            $.ajax({
                url: '<?=url_create('admin','system','detail')?>',
                dataType: 'json',
                data: {id: $(this).attr('data')},
                success: function(o){
                    if(o.state=='success'){
                        var module_groups = '<option value="0"><?=lang('dashboard')?></option>';
                        for(var i in o.data.parents){
                            var r = o.data.parents[i];
                            module_groups+='<option value="'+r.id+'">'+r.pre+r.name+'</option>';
                        }
                        $('#module_name').attr('value',o.data.name);
                        $('#module').attr('value',o.data.controller);
                        $('#module_group').html(module_groups);
						$('#module_group option[value='+o.data.p_id+']').attr('selected','selected');
						$('#module_class').attr('value',o.data.class);
                        $('#module_index').attr('value',o.data.index);
                        $('#module_active').attr('checked',o.data.active==1);
                        $('#module_modal_title').html('<?=lang('module_update')?>');
						$(".os_chbox").iButton("repaint");
						//load_ibutton();
						//$('#module_index').spinner({ min: 0 });
                        $('#module_modal_toggle').click();
						
                        
                    }
                    else
                        $.jGrowl(o.message, {
                            header: o.title,
                            theme:"notification_styled_"+o.state
                        });
                }
            })
        });
        
		$('.module_create').live('click',function(e){
			$('#module_modal').attr('flag','create');
			var module_groups = '<option value="0"><?=lang('dashboard')?></option>'
			$.ajax({
				url: '<?=url_create('admin','system','read')?>',
				dataType: 'json',
				success: function(o){
					if(o.state=='success'){
						var str='<option value="0"><?=lang('dashboard')?></option>';
						for(var i in o.data){
							var r=o.data[i];
							str+='<option value="'+r.id+'">'+r.pre+r.name+'</option>';
						}
						$('#module_group').html(str);
						$('#module_name').attr('value','');
						$('#module').attr('value','');
						
						$('#module_class').attr('value','');
						$('#module_index').attr('value','0');
						$('#module_active').attr('checked',true);


						$('#module_modal_title').html('<?=lang('module_create')?>');
						$(".os_chbox").iButton("repaint");
						$('#module_modal_toggle').click();
					}
					else
					{
						
					}
					
				}
			})
			
		});
        $('#module_modal_ok').live('click',function(e){
			var flag = $('#module_modal').attr('flag');

			$.ajax({
				url: flag=='create'?'<?=url_create('admin','system','create')?>':'<?=url_create('admin','system','update')?>',
				dataType: 'json',
				type: 'post',
				data: {
					id: $('#module_modal').attr('module_id'),
					name: $('#module_name').val(),
					controller: $('#module').val(),
					p_id: $('#module_group').val(),
					class: $('#module_class').val(),
					index: $('#module_index').val(),
					active: $('#module_active').is(':checked')?1:0
				},
				success: function(o){
					if(o.state=='success'){
						$('#module_modal_toggle').click();
						$.jGrowl(o.message, {
							header: '<?=lang('notice')?>',
							theme:"notification_styled_"+o.state 
						});
						load_module_table();
					}
					else{

					}
				}
			});
            
        });
		
        $('#module_modal_cancel').live('click',function(e){
            $('#module_modal_toggle').click();
        });
		/*oTable = $('#module_table').dataTable({		
			"sPaginationType": "full_numbers"
		});*/
        $(document).ready(load_module_table());
    </script>
    